package com.goroom.v_timer;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

public class TimerTest {
    public static void main(String[] args){
        TimerTest test = new TimerTest();
        test.executeTimer();
    }

    public void executeTimer(){
        Timer timer = new Timer();
        TimerTask timerTask = new MyTimerTask();
        //timer.schedule(timerTask, 0, 1000);
        timer.schedule(timerTask, 1000);
    }

    class MyTimerTask extends TimerTask{
        @Override
        public void run() {
            Calendar calendar = Calendar.getInstance();
            System.out.println("["+ Thread.currentThread().getName()+"] " +
                    calendar.get(Calendar.YEAR)  + "-" +
                    calendar.get(Calendar.MONDAY)  + "-" +
                    calendar.get(Calendar.DATE)  + "  " +
                    calendar.get(Calendar.HOUR)  + ":" +
                    calendar.get(Calendar.MINUTE)  + ":" +
                    calendar.get(Calendar.SECOND));
        }
    }
}
